package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CpAthlete;
import com.ruoyi.system.service.ICpAthleteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参赛选手信息Controller
 *
 * @author zhangjinlei
 * @date 2022-04-25
 */
@RestController
@RequestMapping("/system/athlete")
public class CpAthleteController extends BaseController
{
    @Autowired
    private ICpAthleteService cpAthleteService;

    /**
     * 查询参赛选手信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:list')")
    @GetMapping("/list")
    public TableDataInfo list(CpAthlete cpAthlete) throws Exception {
        startPage();
        List<CpAthlete> list = cpAthleteService.selectCpAthleteList(cpAthlete);
        return getDataTable(list);
    }

    /**
     * 导出参赛选手信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:export')")
    @Log(title = "参赛选手信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpAthlete cpAthlete) throws Exception {
        List<CpAthlete> list = cpAthleteService.selectCpAthleteList(cpAthlete);
        ExcelUtil<CpAthlete> util = new ExcelUtil<CpAthlete>(CpAthlete.class);
        util.exportExcel(response, list, "参赛选手信息数据");
    }

    /**
     * 获取参赛选手信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cpAthleteService.selectCpAthleteById(id));
    }

    /**
     * 新增参赛选手信息
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:add')")
    @Log(title = "参赛选手信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpAthlete cpAthlete) throws Exception {
        return toAjax(cpAthleteService.insertCpAthlete(cpAthlete));
    }

    /**
     * 修改参赛选手信息
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:edit')")
    @Log(title = "参赛选手信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpAthlete cpAthlete)
    {
        return toAjax(cpAthleteService.updateCpAthlete(cpAthlete));
    }

    /**
     * 删除参赛选手信息
     */
    @PreAuthorize("@ss.hasPermi('system:athlete:remove')")
    @Log(title = "参赛选手信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cpAthleteService.deleteCpAthleteByIds(ids));
    }
}
